<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>巡检任务管理制定与分配 > 修改</title>
    <!-- BOOTSTRAP STYLES-->
    <link href="../assets/css/bootstrap.css" rel="stylesheet"/>
    <!-- FONTAWESOME STYLES-->
    <link href="../assets/css/font-awesome.css" rel="stylesheet"/>
    <!--CUSTOM BASIC STYLES-->
    <link href="../assets/css/basic.css" rel="stylesheet"/>
    <!--CUSTOM MAIN STYLES-->
    <link href="../assets/css/custom.css" rel="stylesheet"/>
    <!-- GOOGLE FONTS-->
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'/>
    <!-- GOOGLE FONTS-->
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'/>
</head>
<body>
<div id="wrapper">
    <div id="page-inner">
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        巡检任务管理制定与分配 > 修改
                    </div>
                    <div class="panel-body">
                        <div role="form" class="col-md-6 col-sm-6 col-xs-12" method="post">
                            <input type="hidden" id="InspecId" name="InspecId"/>
                            <div class="form-group">
                                <label class="control-label col-lg-4">任务编码</label>
                                <input type="text" class="form-control" id="inspectionTaskCode"
                                       name="inspectionTaskCode" required="required"
                                       placeholder="请输入任务编码"/>
                            </div>

                            <div class="form-group">
                                <label class="control-label col-lg-4">任务名称</label>
                                <input name="inspectionTaskName" id="inspectionTaskName" type="text"
                                       class="form-control"
                                       required="required"
                                       placeholder="请输入任务名称"/>
                            </div>


                            <div class="form-group">
                                <label for="lineName">巡检线路</label>
                                <select class="form-control" id="lineName" name="lineName">
                                    <option value="--请选择--">--请选择--</option>
                                    <option value="西渭一线">西渭一线</option>
                                    <option value="西渭二线">西渭二线</option>
                                    <option value="西渭三线">西渭三线</option>
                                    <option value="西渭四线">西渭四线</option>
                                    <option value="西城一线">西城一线</option>
                                    <option value="西临1号线">西临1号线</option>
                                </select>
                            </div>

                            <div class="form-group">
                                <label for="issuedByName">巡检员</label>
                                <textarea class="form-control" rows="3" id="xunjianyuan" name="issuedByName"></textarea>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-lg-4">起始杆号</label>
                                <input class="form-control" id="startPoleCode" name="startPoleCode" type="text">
                            </div>
                            <div class="form-group">
                                <label class="control-label col-lg-4">终止杆号</label>
                                <input class="form-control" id="endPoleCode" name="endPoleCode" type="text">
                            </div>


                            <div class="form-group">
                                <label class="control-label col-lg-4">下发人</label>
                                <input class="form-control" id="issuedByName" name="issuedByName" type="text" disabled>
                            </div>

                            <div class="form-group">
                                <label class="control-label col-lg-4">修改日期</label>
                                <input class="form-control" id="lastUpdateTime" name="lastUpdateTime" type="text" disabled>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-lg-4">备注</label>
                                <textarea class="form-control" rows="3" id="common"></textarea>

                            </div>
                            <div class="form-group">
                                <div class="col-sm-12">
                                    <button class="btn btn-info col-sm-12" id="Inspectionupdate">提交</button>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="../assets/js/jquery.min.js"></script>
<!-- BOOTSTRAP SCRIPTS -->
<script src="../assets/js/bootstrap.min.js"></script>
<script>
    $(function () {
        getTimeAndInit();
        updateInspection();
    })

    //获取当前时间和当前登录的用户，初始化页面【获取该巡检任务的信息】
    function getTimeAndInit() {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var time = year + "-" + month + "-" + day;
        $("#lastUpdateTime").val(time);


        var InspecId = sessionStorage.getItem("inspeId");
        var url = "http://localhost:8080/inspectask/" + InspecId;
        $.getJSON(url, null, function (data) {
            var inspection = data.obj;
            var inspectionTaskCode = data.obj.inspectionTaskCode;
            var inspectionTaskName = data.obj.inspectionTaskName;
            var lineName = data.obj.lineName;
            var startPoleCode = data.obj.startPoleCode;
            var endPoleCode = data.obj.endPoleCode;
            var issuedByName = data.obj.issuedByName;
            var lastUpdateTime = data.obj.issuedTime;
            var common = data.obj.common;
            var xunjianyuan = localStorage.getItem(inspectionTaskCode);


            $("#inspectionTaskCode").val(inspectionTaskCode);
            $("#inspectionTaskName").val(inspectionTaskName);
            $("#lineName").val(lineName);
            $("#startPoleCode").val(startPoleCode);
            $("#endPoleCode").val(endPoleCode);
            $("#issuedByName").val(issuedByName);
            $("#lastUpdateTime").val(lastUpdateTime);
            $("#common").val(common);
            $("#xunjianyuan").val(xunjianyuan);
            $("#InspecId").val(InspecId);
        })


    }

    function updateInspection() {
        $("#Inspectionupdate").click(function () {
            var inspectionTaskCode = $("#inspectionTaskCode").val().trim();
            var InspecId = $("#InspecId").val().trim();
            var inspectionTaskName = $("#inspectionTaskName").val().trim();
            var lineName = $("#lineName").val().trim();
            var xunjianyuan = $("#xunjianyuan").val().trim();
            var startPoleCode = $("#startPoleCode").val().trim();
            var endPoleCode = $("#endPoleCode").val().trim();
            var issuedByName = $("#issuedByName").val().trim();
            var lastUpdateTime = $("#lastUpdateTime").val().trim();
            var common = $("#common").val().trim();

            var addInspectionJson = {
                "id": InspecId,
                "inspectionTaskCode": inspectionTaskCode,
                "inspectionTaskName": inspectionTaskName,
                "lineName": lineName,
                "xunjianyuan": xunjianyuan,
                "startPoleCode": startPoleCode,
                "endPoleCode": endPoleCode,
                "issuedByName": issuedByName,
                "lastUpdateTime": lastUpdateTime,
                "common": common
            };
            $.ajax({
                url: 'http://localhost:8080/inspectask/',
                type: 'PUT',
                data: JSON.stringify(addInspectionJson),
                dataType: "json",
                contentType: "application/json;charset=UTF-8",
                success: function (data) {
                    if (data.status == 200) {
                        localStorage.setItem(inspectionTaskCode, xunjianyuan);
                        window.location.href = 'FormuAndDist.html';
                    }
                },
                error: function () {
                    alert("error")
                }
            })
        })
    }
</script>

</body>
</html>
